define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mental/order/index' + location.search,
                    add_url: 'mental/order/add',
                    edit_url: 'mental/order/edit',
                    del_url: 'mental/order/del',
                    multi_url: 'mental/order/multi',
                    table: 'mental_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'createtime',
                queryParams:function(params){
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    var eid = Fast.api.query('ids');  
                    console.log(eid)
                    if (eid) {
                          filter.extensionId = eid;
                          op.extensionId = '=';
                          params.filter = JSON.stringify(filter);
                          params.op = JSON.stringify(op);
                        //   funcUrlDel('ids');
                    }
                    return params;
                  
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_id', title: __('Order_id')},
                        // {field: 'type', title: __('Type'),  searchList:{"0":"付费测试","1":"完整解读","2":"只看结果","3":"人工解读","4":"赠TA测","5":"补差价","6":"企业团体"}, formatter: Table.api.formatter.normal},
                        {field: 'title', title: __('Main_id'),operate:false},
                        // {field: 'invitation_code', title: __('邀请码')},
                        {field: 'user.nickname', title: __('User_id'),operate:false},
                        {field: 'amount', title: __('Amount'),operate:false},
                        
                        {field: 'payamount', title: __('Payamount'),operate:false},
                        
                        {field: 'url', title: __('Url'), operate: false, formatter: Table.api.formatter.url},
                        // {field: 'qrcode', title: __('Image'), operate: false, formatter: function(value,row,index){
                        //
                        //     return '<a href="'+value+'" download="" style="text-decoration:none;color:#333;"><img src="'+value+'" alt="" style="width:35px;height:35px;"/><span style="font-size:8px;">点击下载</span></a>';
                        // }},
                        // {field: 'ip', title: __('Ip')},
                       // {field: 'useragent', title: __('Useragent')},
                        {field: 'paytype_text', title: __('Paytype'),operate:false},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate:false},
                        // {field: 'extensionId', title: __('分销ID')},
                        // {field: 'channel_type_text', title: __('分销渠道'),operate:false},
                        // {field: 'commission', title: __('Commission'),operate:false},
                        {field: 'status', title: __('Status'), searchList: {"created":__('Created'),"paid":__('Paid'),"expired":__('Expired')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});